<template>
  <div class="tablewrap">
    <div>预约安排</div>
    <FilterTable
      :columns="columns"
      :isColumnFilter="false"
      :dataSource="dataSource"
      :height="200"
      selectionType="single"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="rowSelectChange"
    ></FilterTable>
  </div>
</template>

<script>
import moment from 'moment';
import { queryBookingOrder } from '@/api/repair/repairReception/customer/monitoring.js';
import { dictionary } from '@/utils/dictMixin';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';

export default {
  name: 'YuYueAnPai',
  mixins: [dictionary],
  props: {
    queryParams: Object
  },
  data() {
    return {
      // 预约安排
      dataSource: [],
      columns: this.createColumnsAppointment()
    };
  },
  mounted() {
    this.queryBookingOrder();
  },
  created() {
    this.getEmp();
  },
  methods: {
    rowSelectChange(opt) {
      console.log(opt);
      // this.selectRow = opt
      this.$emit('selectChange', opt);
    },
    async queryBookingOrder() {
      const params = {
        sort: 'BOOKING_ORDER_NO',
        order: 'asc',
        limit: 10,
        offset: 0,
        ...this.queryParams
        // LICENSE: '陕A2FU00',
        // vin: '09876543219876543',
        // ownerNo: 'OW1907110001',
        // BRAND: 'LINCOLN',
        // MILEAGE: 999999,
        // isRepairOrder: 'REPAIR_ORDER_TAG',
        // createDate: moment().format('YYYY-MM-DD HH-mm'),
        // dmsFuncId: 35100010,
        // _: moment().valueOf()
      };
      console.log(params);
      const res = await queryBookingOrder(params);
      console.log('预约安排', params, res);
      this.dataSource = res.data.rows;
    },
    createColumnsAppointment() {
      return [
        {
          title: '序号',
          width: 50,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '预约单号',
          dataIndex: 'BOOKING_ORDER_NO'
        },
        {
          title: 'VIN',
          dataIndex: 'VIN'
        },
        {
          title: '预约类别',
          dataIndex: 'BOOKING_TYPE_CODE',
          render: props => {
            return <span>{this.createDictText(props.row.BOOKING_TYPE_CODE, '8055')}</span>;
          }
        },
        {
          title: '预约进厂时间',
          dataIndex: 'BOOKING_COME_TIME',
          dateFormat: 'yyyy-MM-dd HH:mm:ss'
        },
        {
          title: '联系人',
          dataIndex: 'CONTACTOR_NAME'
        },
        {
          title: '指定技师',
          dataIndex: 'CHIEF_TECHNICIAN',
          render: props => {
            return <span>{this.getEmployeeName(props.row.CHIEF_TECHNICIAN)}</span>;
          }
        },
        {
          title: '锁定人',
          dataIndex: 'LOCK_USER'
        },
        {
          title: '创建时间',
          dataIndex: 'CREATED_AT',
          dateFormat: 'yyyy-MM-dd HH:mm:ss'
        },
        {
          title: '备注',
          dataIndex: 'REMARK'
        }
      ];
    },
    // 获取员工信息并转义
    async getEmp() {
      const res = await getDealerUser();
      this.serviceAdvisorData = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
      // this.columns.find(x => x.dataIndex === 'CREATED_BY').editItems = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
      // this.columns.find(x => x.dataIndex === 'LOCK_USER').editItems = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
    },
    // 转换数据
    getEmployeeName(userId) {
      const item = this.serviceAdvisorData.find(x => {
        return x.value == userId;
      });
      return item ? item.text : '';
    }
  }
};
</script>

<style scoped></style>
